package com.cqcj.wms.service.impl;

import com.cqcj.wms.entity.StoreMain;
import com.cqcj.wms.entity.StoreSub;
import com.cqcj.wms.mapper.StoreMainMapper;
import com.cqcj.wms.mapper.StoreSubMapper;
import com.cqcj.wms.service.IStoreMainService;
import com.cqcj.wms.service.IStoreSubService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：zhouxiaobao
 * @name：IStoreSubServiceImpl
 * @Date：2024/10/17 14:41
 */
@Service
public class IStoreSubServiceImpl implements IStoreSubService{

    @Autowired
    private StoreSubMapper storeSubMapper;

    @Override
    public List<StoreSub> list() {
        return storeSubMapper.list();
    }

    @Override
    public int insert(StoreSub storeSub) {
        return storeSubMapper.insert(storeSub);
    }

    @Override
    public int update(StoreSub storeSub) {
        return storeSubMapper.update(storeSub);
    }

    @Override
    public int delete(int id) {
        return storeSubMapper.delete(id);
    }

    @Override
    public StoreSub getEntityById(int id) {
        return storeSubMapper.getEntityById(id);
    }

    @Override
    public PageInfo<StoreSub> pageList(int pageNum, int pageSize) {
        if(pageNum < 1){
            pageNum = 1;
        }
        //借助PageHelper工具类开启分页
        PageHelper.startPage(pageNum, pageSize);
        //查询仓库列表
        List<StoreSub> goodList = storeSubMapper.list();
        //将仓库列表信息封装到PageInfo对象中
        PageInfo<StoreSub> pageInfo = new PageInfo<>(goodList);
        return  pageInfo;
    }

    /**
     * 根据条件查询分页
     * @param pageNum 当前页
     * @param pageSize 当前页数
     * @param storeSub 对象
     * @return
     */
    @Override
    public PageInfo<StoreSub> listByConditions(int pageNum, int pageSize, StoreSub storeSub) {
        if(pageNum < 1){
            pageNum = 1;
        }
        //借助PageHelper工具类开启分页
        PageHelper.startPage(pageNum, pageSize);
        //查询仓库列表
        List<StoreSub> storeSubList = storeSubMapper.listByConditions(storeSub);
        //将仓库列表信息封装到PageInfo对象中
        PageInfo<StoreSub> pageInfo = new PageInfo<>(storeSubList);
        return pageInfo;
    }

    /**
     * 根据供应商id查询入库记录
     * @param storageId
     * @return
     */
    @Override
    public List<StoreSub> lists(int storageId) {
        StoreSub storeSub = new StoreSub();
        storeSub.setStorageId(storageId);
        return storeSubMapper.listByConditions(storeSub);
    }

}
